<?php
class Control_Recharge_getData {

	function getData() {
		$action = $this->getValue("action");
		$date 	= $this->getValue("date");
		
		if(empty($date)) {
			$date = date("Y-m-d");
		}
		
		if($action == 0) {
			$postData['game'] = MooConfig::get('realtimerecharge.defaultGame');
			$realtimerecharge = MooConfig::get('realtimerecharge.url');
			$res = MooUtil::curl_send($realtimerecharge, $postData);
			
			MooView::set('game', $postData['game']);
			MooView::set('date', date("Y-m-d"));
			
			MooView::set('year', date("Y"));
			MooView::set('month', date("m"));
			MooView::set('day', date("d"));
			
			if($res) {
				MooView::set('realTimedata', $res);
			}
			
			MooView::render('getData');
		} else if ($action == 1) {
			
			$postData = array();
			
			$nowGame = $postData['game'] 		= $this->getValue("game");
			$postData['game'] = MooObj::get('Game')->transportGame($postData['game']);
			
			if($_REQUEST['platform']) {
				$postData['platform'] 	= $this->getValue("platform");
			}
			
			if($_REQUEST['channel']) {
				$nowChannel = $postData['channel'] 	= $this->getValue("channel");
				$channel_lang = MooConfig::get("channel_lang.{$game}");
				if($channel_lang['zh_en'][$postData['channel']]) {
					$postData['channel'] = $channel_lang['zh_en'][$postData['channel']];
				}
			}
			
			MooObj::get('Control_Data')->setPlatformData($postData['game']);
			
			MooView::set('nowGame', $nowGame);
			MooView::set('game', $postData['game'] );
			MooView::set('channel', $nowChannel);
			MooView::set('platform', $postData['platform']);
			MooView::set('date', date("Y-m-d"));
			
			// 当天自动刷新 非当天不刷新
			if($date == date('Y-m-d')) {
				MooView::set('autoflush', 1);				
			} else {
				MooView::set('autoflush', 0);
			}
			$postData['date'] = $date;
			
			MooView::set('date', $date);
			MooView::set('year', date("Y"));
			MooView::set('month', date("m") - 1);
			MooView::set('day', date("d"));
			
			$realtimerecharge = MooConfig::get('realtimerecharge.url');
			$res = MooUtil::curl_send($realtimerecharge, $postData);

			if($res) {
				MooView::set('realTimedata', $res);
			}
			
			MooView::render('getData'); 
		}
	}
	
	/**
	 * 获取request的值
	 * @param unknown $key
	 * @return unknown|boolean
	 */
	private function getValue($key) {
		if(isset($_REQUEST[$key])) {
			return $_REQUEST[$key];
		} else {
			return false;
		}
	}
	
}